%html{lang: "ar"}
  %body
    %div
      / //-----------Main Content Area ---------//
      .row
        .col-md-12
          .wrapper
            .row.bottom-bordered
              .col-md-3
                .title-font.gray-text
                  %span
                    يوم متبقى
                  %span 
                    = (45 - ((Time.now - @initiative.created_at) / (3600*24)).round) 

                .md-title.green-font
                  %span
                    = @supporters
                  %span /25000
                .light-green-font.title-font شخص دعم المبادرة
                .progress
                  .progress-bar.progress-bar-success{"aria-valuemax" => "100", "aria-valuemin" => "0", "aria-valuenow" => "40", role: "progressbar", style: "width: #{@support_percent}%"}
                    %span.sr-only 40% Complete (success)
                .inner_menu
                  
                  /////////Make new vote for the poll////////////
                - if @poll_exist == true
                  .main_title.small-text تصويت الحالى 
                  %br
                  .md-title.green-font
                    = @users_who_voted_for_ans_question.length
                    %br
                  .light-green-font.title-font شخص قام بالتصويت
                  %br
                  
                  - if @user_voted_before == false
                    .poll-results
                      .green-font.bold-font
                        - for question in @poll.questions
                          = question.content
                          %br
                        
                      %form{action:"poll_submit"}
                        %input{name: "usr_id", type: "hidden", value: current_user.id }/
                        %input{name: "initiative_id", type: "hidden", value: @initiative.id  }/

                        - for answer in question.answers
                          = answer.content
                          %input{name: "ans_id", type: "radio", value: answer.id}/
                          
                          %br/
                        %input.btn.green-btn{type: "submit", value: "تصويت"}/
                  - else
                    .green-font تم التصويت مسبقا

                    %br
                    - @all_answers_of_question.each do |answer|
                      .green-font
                        = answer.content

                        %br
                        .progress
                          - percentage_of_votes = number_to_percentage(((answer.users.length.to_f/@users_who_voted_for_ans_question.length.to_f)*100),precision: 0)
                          .progress-bar{"aria-valuemax" => "100", "aria-valuemin" => "0", "aria-valuenow" => "2", role: "progressbar", style: "width:#{percentage_of_votes};"}
                          = percentage_of_votes

                //Survay Question
                %br
                - if (@survay_exist == true)
                  %br
                  .inner_menu
                  .main_title.small-text السؤال الحالي
                  %br
                  .green-font.bold-font
                    = @survay.question
                  %br
                  - if @user_answered_before == false
                    = render 'feedback'
                  - else 
                    .green-font تم الإجابة مسبقا
        
                 
                // Make new poll for this initiative
                - if @initiative.user_id == current_user.id
                  %form{action: "/polls/new"}
                    %input{name: "initiative_id", value: @initiative.id, type: "hidden"}
                    %input{type: "submit", value: "اضف تصويت جديد",class: "red-btn"}
                    

                // Make new update for this initiative
                - if @initiative.user_id == current_user.id
                  %form{action: "/update/new"}
                    %input{name: "initiative_id", value: @initiative.id, type: "hidden"}
                    %input{type: "submit", value: "اضف تحديث",class: "red-btn"}

                // Make new survay question for this initiative
                - if @initiative.user_id == current_user.id
                  %form{action: "/survays/new"}
                    %input{name: "initiative_id", value: @initiative.id, type: "hidden"}
                    %input{type: "submit", value: "اضف سؤال",class: "red-btn"}
                  
                      
           
              .col-md-9
                .cause-wrapper
                  .row.cause-wrapper-row
                    .col-md-12.cause-wrapper-header
                      .row
                        .col-md-9
                          .col-md-4
                            -if @supportFlag == []
                              %form{action: "/supports/support"}
                                %input{name: "initiative_id", type: "hidden", value: @initiative.id }/
                                .btn.red-btn
                                  = button_to "إدعم مبادرة"    
                            - else
                              .col-md-3
                              .support-mark.col-md-9
                                = image_tag "support-mark.png"
                              %span.col-md-12.green-font
                                تم دعم هذه المبادرة
                              
                          .col-md-8
                            .cause-wrapper-title.green-font
                              = @initiative.title
                            .cause-wrapper-sub-title

                              مبادرة فى
                              %span.green-font 
                                #{link_to(@initiative.sector.name, {:controller => 'initiatives' ,:action => "list", :sector_name => @initiative.sector.name})}
                              \- بإمارة
                              %span.green-font 
                                #{link_to(@initiative.region.name, {:controller => 'initiatives' ,:action => "list", :region_name => @initiative.region.name})}
                          .col-md-12
                            #{link_to(@initiative.user.name, {:controller => 'users' ,:action => "show", :user_id => @initiative.user.id})}
                            .social-media-sharing
                            
                            .cause-wrapper-sub-title :التصنيفات
                            .cause-wrapper-details.gray-text.green-font                             
                              - for tag in @initiative.tags
                                #{link_to(tag.name, {:controller => 'initiatives' ,:action => "list", :tag => tag.name})}

                                                          
                        .col-md-3
                          .cause-wrapper-img
                            = image_tag @initiative.image.url 
                          
                      
                    .row.cause-wrapper-paragraph
                      .col-md-12
                        .green-font.bold-font تفاصيل المبادرة
                        .cause-wrapper-details.gray-text
                          = @initiative.description.html_safe
                  .cause_discussion_block
 
                - @update_result.each do |update_or_result|
                  - if @created_at_updates.include?(update_or_result.created_at)
                    .row
                      .col-md-12
                        .timeline

                          .timeline-wrapper
                            .pre-timeline-date.gray-text
                              %div= update_or_result.created_at.to_time.strftime('%A')
                              .green-font.bold 
                                = update_or_result.created_at.to_time.strftime('%B %e')
                              %div= update_or_result.created_at.to_time.strftime('%Y')
                            .circle-icon.green-icon
                            .timeline-item.small-item.plain-timeline-item
                              .timeline-item-wrapper
                                .green-font.bold 
                                  %span تحديث #
                                  = @count
                                  - @count-=1
                                .timeline-item-details.gray-text
                                  = update_or_result.action.html_safe
                                   
                  - else

                    - user=update_or_result.decisionmakers.first
                    .row
                      .col-md-12
                        .timeline
                          .timeline-wrapper
                            .pre-timeline-date.gray-text
                              %div= update_or_result.created_at.to_time.strftime('%A')
                              .red-font.bold= update_or_result.created_at.to_time.strftime('%B %e')
                              %div= update_or_result.created_at.to_time.strftime('%Y')
                            .circle-icon.red-icon
                            .timeline-item.medium-item.upper-image-timeline-item
                              .timeline-item-wrapper
                                .red-font.bold النتائج الرسمية
                                .row
                                  .col-md-10
                                    .timeline-item-supporter
                                      .green-font.timeline-item-supporter-title
                                        = user.name
                                      .green-font.timeline-item-supporter-sub-title
                                        = user.job
                                      .light-text.timeline-item-supporter-sub-date
                                        تاريخ 
                                        = update_or_result.created_at.to_time.strftime('%A %e %B  %Y ')

                                  .col-md-2
                                    .timeline-item-supporter-img
                                      = image_tag "atef-helmy.jpg"
                                %br
                                .timeline-item-details.gray-text
                                  .green-font
                                    تفاصيل القرار
                                  = update_or_result.decision.html_safe

                                    
                    
                          
            %br/
            .row
              .col-md-3
              .col-md-9
                .inner_menu
                  .main_title مناقشة المبادرة

                %form{action: "/comments/create",remote: true}
                  .send-comment
                    %textarea.form-control{cols: "30", name: "content", rows: "6"}
                    %input{name: "initiative_id", type: "hidden", value: @initiative.id }/
                    %input.btn.green-btn{type: "submit", value: "ارسل"}/
                - @comments.each do |comment|
                  .cause_discussion_block
                    .row
                      .col-md-10
                        .col-md-2
                          %span.cause_discussion_time.gray-text
                            - if ((Time.now - comment.created_at) / 3600).round < 24
                              = ((Time.now - comment.created_at) / 3600).round
                              %span h
                            - else 
                              = ((Time.now - comment.created_at) / (3600*24)).round
                              %span d 
                        .col-md-10
                          %span.cause_discussion_paragraph.title-font
                            #{link_to(comment.user.name, {:controller => 'users' ,:action => "show", :user_id => comment.user.id})}
                        .col-md-12
                          %span.cause_discussion_paragraph
                            = comment.content
                      .col-md-2
                        .cause_discussion_img
                          = image_tag comment.user.image.url




